#pragma once

#include <iostream>
#include "log.hpp"
#include <string>
#include <cerrno>
#include <cstring>

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

class TcpServer
{
public:
    TcpServer(uint16_t port, std::string ip = "")
        :_port(port)
        ,_ip(ip)
        ,_sock(-1)
    {}
    void initServer()
    {
        // 1.创建套接字 -- 进程和文件
        _sock = socket(AF_INET, SOCK_STREAM, 0);
        if (_sock < 0)
        {
            logMessage(FATAL, "%d:%s", errno, strerror(errno));
            exit(2);
        }
        logMessage(NORMAL, "create socket success, _sock: %d", _sock); //3
        // 2. bind
        struct sockaddr_in local;
    }
    void start()
    {}
    ~TcpServer(){};
private:
    uint16_t _port;
    std::string _ip;
    int _sock;
};